import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/items/labItems/list',
  save='/items/labItems/add',
  edit='/items/labItems/edit',
  deleteOne = '/items/labItems/delete',
  deleteBatch = '/items/labItems/deleteBatch',
  importExcel = '/items/labItems/importExcel',
  exportXls = '/items/labItems/exportXls',
  queryByPid='/items/labItems/queryByPid',

  basicList = '/items/labItemsTemp2Basic/list',
  basicSave='/items/labItemsTemp2Basic/add',
  basicEdit='/items/labItemsTemp2Basic/edit',
  basicDelOne = '/items/labItemsTemp2Basic/delete',
  // basicDelBatch = '/items/labItemsTemp2Basic/deleteBatch',
  basicQueryById='/items/labItemsTemp2Basic/queryById',

  personList = '/items/labItemsTemp2Person/list',

  targerMList = '/items/labItemsTarget/list',
  targetList = '/items/labItemsTemp2Target/list',
  addTarget = '/items/labItemsTemp2Target/addTarget',


}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params?) => defHttp.get({ url: Api.list, params });

/**
 * 根据父类id查询
 * @param params 
 * @returns 
 */
export const queryByPid=(params)=>defHttp.get({url:Api.queryByPid,params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

/**
 * 列表接口
 * @param params
 */
export const basicList = (params?) => defHttp.get({ url: Api.basicList, params });


/**
 * 根据id查询
 * @param params 
 * @returns 
 */
export const basicQueryById=(params)=>defHttp.get({url:Api.basicQueryById,params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const basicDelOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.basicDelOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const basicSaveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.basicSave : Api.basicEdit;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}


/**
 * 列表接口
 * @param params
 */
export const personList = (params?) => defHttp.get({ url: Api.personList, params });



/**
 * 列表接口
 * @param params
 */
export const targerMList = (params?) => defHttp.get({ url: Api.targerMList, params });

/**
 * 列表接口
 * @param params
 */
export const targetList = (params?) => defHttp.get({ url: Api.targetList, params });

/**
 * 保存或者更新
 * @param params
 */
export const addTarget = (params) => {
  return defHttp.post({ url: Api.addTarget, params }, { isTransformResponse: false });
}

